package com.prj.ufdm.cloud.ms.auth.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.prj.ufdm.cloud.base.dto.RetData;
import com.prj.ufdm.cloud.base.exception.BaseException;
import com.prj.ufdm.cloud.base.util.BaseStringUtil;
import com.prj.ufdm.cloud.ms.auth.bpo.SysUserDutyBPO;
import com.prj.ufdm.cloud.ms.auth.enums.AuthRetCodeEnum;

/**
 * DESC: 职务机构控制类 <br>
 * @author 胡义振
 * @date 2020年1月15日
 */
@RequestMapping(value = "/api/auth/sysuserduty")
@Controller
public class SysUserDutyController {
	
	@Autowired
	SysUserDutyBPO sysUserDutyBPO;
	
	
	/**
	 * 职务添加用户
	 * @param 
	 *      dutyId   角色ID
	 *      userIds  用户ID（多个用","号分隔）
	 * @return
	 * @author 胡义振  
	 * @date 2018年3月26日
	 */
	@RequestMapping(value = "/doAddDutyUser")
	@ResponseBody
	public RetData<String> doAddDutyUser(String dutyId,String userIds) throws Exception {
		RetData<String> retData = new RetData<String>();
		// 角色ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(dutyId))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0106001.getCode(),AuthRetCodeEnum.RET_CODE_0106001.getMessage());
		}
		// 功能ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(userIds))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0106003.getCode(),AuthRetCodeEnum.RET_CODE_0106003.getMessage());
		}
		sysUserDutyBPO.doAddDutyUser(dutyId, userIds);
		return retData;
	}
	
	/**
	 * 职务添加用户
	 * @param 
	 *      userId   用户ID
	 *      dutyIds  职务ID（多个用","号分隔）
	 * @return
	 * @author 胡义振  
	 * @date 2018年3月26日
	 */
	@RequestMapping(value = "/doAddUserDuty")
	@ResponseBody
	public RetData<String> doAddUserDuty(String userId,String dutyIds) throws Exception {
		RetData<String> retData = new RetData<String>();
		// 角色ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(userId))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0106003.getCode(),AuthRetCodeEnum.RET_CODE_0106003.getMessage());
		}
		// 功能ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(dutyIds))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0106003.getCode(),AuthRetCodeEnum.RET_CODE_0106003.getMessage());
		}
		sysUserDutyBPO.doAddUserDuty(userId, dutyIds);
		return retData;
	}
	
	/**
	 * 删除用户职务对应关系
	 * @param 
	 *      userId   用户ID
	 *      dutyId  职务ID（多个用","号分隔）
	 * @return
	 * @author 胡义振  
	 * @date 2018年3月26日
	 */
	@RequestMapping(value = "/doDeleteUserDuty")
	@ResponseBody
	public RetData<String> doDeleteUserDuty(String userId,String dutyId) throws Exception {
		RetData<String> retData = new RetData<String>();
		// 角色ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(userId))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0106003.getCode(),AuthRetCodeEnum.RET_CODE_0106003.getMessage());
		}
		// 功能ID不能为空
		if("".equals(BaseStringUtil.replaceAllBlank(dutyId))) {
			throw new BaseException(AuthRetCodeEnum.RET_CODE_0106001.getCode(),AuthRetCodeEnum.RET_CODE_0106001.getMessage());
		}
		
		sysUserDutyBPO.doDelUserDuty(userId, dutyId);
		return retData;
	}
	
	
}
